package com.punai.standard.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.core.domain.TreeBo;
import com.punai.standard.domain.StaJxChapter;
import com.punai.standard.mapper.StaJxChapterMapper;
import com.punai.standard.service.IStaJxChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 机械章节Service业务层处理
 *
 * @author zhx
 * @date 2022-12-21
 */
@Service
public class StaJxChapterServiceImpl extends ServiceImpl<StaJxChapterMapper,StaJxChapter> implements IStaJxChapterService
{
    @Autowired
    private StaJxChapterMapper staJxChapterMapper;
    
    @Override
    public List<TreeBo> treeData(String versionsId) {
        List<TreeBo> result = new ArrayList<>();
        LambdaQueryWrapper<StaJxChapter> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StaJxChapter::getVersionId,versionsId);
        List<StaJxChapter> chapters = staJxChapterMapper.selectList(queryWrapper);
        if (CollUtil.isEmpty(chapters)) {
            return result;
        }
        result = TreeBo.convert(chapters);
        return result;
    }
}
